<template>
  <div class="panel-card">
    <div class="panel-header">
      <h3 class="panel-title">统计信息</h3>
      <button 
        class="refresh-btn"
        @click="handleRefresh"
        title="刷新统计信息"
      >
        🔄
      </button>
    </div>
    
    <!-- 统计卡片 -->
    <div class="stats-grid">
      <div class="stat-card">
        <div class="stat-value">{{ stats.total }}</div>
        <div class="stat-label">总文档数</div>
      </div>
      <div class="stat-card">
        <div class="stat-value">{{ stats.indexed }}</div>
        <div class="stat-label">已索引</div>
      </div>
      <div class="stat-card">
        <div class="stat-value">{{ stats.processing }}</div>
        <div class="stat-label">处理中</div>
      </div>
      <div class="stat-card">
        <div class="stat-value">{{ stats.totalSizeFormatted }}</div>
        <div class="stat-label">总大小</div>
      </div>
    </div>
    
    <!-- 最近活动 -->
    <div class="panel-section">
      <h4>最近活动</h4>
      <div class="activity-list">
        <div v-if="recentActivities.length === 0" class="empty-activity">
          <p>暂无活动记录</p>
        </div>
        <div 
          v-for="(activity, index) in recentActivities" 
          :key="index"
          class="activity-item"
        >
          <div class="activity-icon">{{ activity.icon }}</div>
          <div class="activity-content">
            <div class="activity-text">{{ activity.text }}</div>
            <div class="activity-time">{{ activity.time }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'StatisticsPanel',
  props: {
    stats: {
      type: Object,
      default: () => ({
        total: 0,
        indexed: 0,
        processing: 0,
        totalSize: 0,
        totalSizeFormatted: '0 Bytes'
      })
    },
    recentActivities: {
      type: Array,
      default: () => []
    }
  },
  emits: ['refreshStats'],
  methods: {
    handleRefresh() {
      this.$emit('refreshStats');
    }
  }
};
</script>

<style scoped>
.panel-card {
  background: white;
  border-radius: 10px;
  padding: 25px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  height: fit-content;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.panel-title {
  font-size: 1.3rem;
  color: #2c3e50;
  margin: 0;
}

.refresh-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid #e1e5e9;
  background: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.refresh-btn:hover {
  background: #f8f9fa;
  transform: rotate(180deg);
  transition: transform 0.5s ease;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin-bottom: 30px;
}

.stat-card {
  text-align: center;
  padding: 20px;
  border-radius: 8px;
  background: #f8f9fa;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.stat-value {
  font-size: 1.8rem;
  font-weight: bold;
  color: #1976d2;
  margin-bottom: 5px;
}

.stat-label {
  color: #6c757d;
  font-size: 0.9rem;
}

.panel-section {
  border-top: 1px solid #e1e5e9;
  padding-top: 20px;
}

.panel-section h4 {
  margin: 0 0 15px 0;
  color: #2c3e50;
  font-size: 1.1rem;
}

.activity-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.activity-item {
  display: flex;
  gap: 15px;
  padding: 10px;
  border-radius: 6px;
  background: #f8f9fa;
  transition: background 0.3s ease;
}

.activity-item:hover {
  background: #e9ecef;
}

.activity-icon {
  font-size: 1.2rem;
  align-self: flex-start;
  width: 20px;
  text-align: center;
}

.activity-content {
  flex: 1;
}

.activity-text {
  margin-bottom: 5px;
  color: #2c3e50;
  font-size: 0.95rem;
}

.activity-time {
  font-size: 0.85rem;
  color: #6c757d;
}

.empty-activity {
  text-align: center;
  padding: 40px 20px;
  color: #6c757d;
}

.empty-activity p {
  margin: 0;
}

@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}
</style>